home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
- Path: Utrecht.NL.net!news
- From: Franz Korntner <fkorntne@bazis.nl>
- Subject: Re: Access carry flag from C
- X-Nntp-Posting-Host: bastion1.bazis.nl
- Content-Type: text/plain; charset=us-ascii
- Message-ID: <312AFACE.41C6@bazis.nl>
- Sender: news@inter.NL.net (News at newsutr)
- Content-Transfer-Encoding: 7bit
- Organization: NLnet
- References: <Dn1C9z.DGv.0.net@indra.com> <1996Feb1922.17.19.879@koobera.math.uic.edu> <31298D20.41C6@bazis.nl> <danpop.824859220@rscernix>
- Mime-Version: 1.0
- Date: Wed, 21 Feb 1996 10:58:22 GMT
- X-Mailer: Mozilla 2.0b6a (X11; I; OSF1 V3.2 alpha)
-
- Dan Pop wrote:
- >
- > In <31298D20.41C6@bazis.nl> fkorntne@bazis.nl (Franz Korntner) writes:
- >
- > >Steve Sullivan <sullivan@indra.com> wrote:
- > >> i = j + k;
- > >> if (overflowed) ....;
- > >
- > >Yes there is a method.
- > >
- > >j+k will overflow when the result exceeds MAXINT
- > >
- > >Thus: "if (j+k > MAXINT) overflow();" but the operation is undefined
- > >if the result overflows, so the expression needs rewriting to make sure
- > >this doesn't happen. The result is then "if (j>MAXINT-k) overflow();".
- >
- > If k is negative, MAXINT-k will overflow :-)
-
- Later I pointed out that this was only true for unsigned numbers. Why
- should I start with the difficult case first?
-
- > BTW, MAXINT is spelled INT_MAX in C.
-
- I know that and I named it so deliberatly. Because we are testing overflow
- of arithmetic operations we must be aware of the size of the variables. In
- my example I didn't mention the type 'int', I just stated that I assumed
- 32 bit numbers. According to the (X3J11 / ANSI) standard, the constant
- INT_MAX (and in this case most limits in limits.h) denotes the minimal
- limit. It is possible that the physical limit is much higher (or lower
- in the case of negative values). As I am only interested in the physical
- limit, the value INT_MAX has no meaning. Only the compiler is fully aware
- of these limits (and not a header file!) and what I really miss in the
- standard and/or implementation is a inline function 'maxlimitof(int)',
- analogical to 'sizeof(int)'.
-
- What will the future hold for 64 bit or larger machines. For the Alpha
- they declared int to be a 32 bit datatype because too many coders relied
- on this. Real pity as int should denote the natural size of the machine,
- and in the case of the Alpha it should have been 64! But this is a
- totally different discussion.
-
- --
- +-----------------------------------------------------------------------+
- | Franz Korntner at BAZIS, dept. System Development, Leiden, Netherlands|
- | E-mail: fkorntne@hiscom.nl |
- +-----------------------------------------------------------------------+
-